/*
 * libkysdk-waylandhelper's Library
 *
 * Copyright (C) 2023, KylinSoft Co., Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library.  If not, see <https://www.gnu.org/licenses/>.
 *
 * Authors: Zhen Sun <sunzhen1@kylinos.cn>
 *
 */

#ifndef WINDOWMANAGER_H
#define WINDOWMANAGER_H

#include <QObject>
#include <QString>
#include <QIcon>
#include "windowinfo.h"
#include "wmregister.h"

namespace kdk
{
using WindowId = QVariant;
class WindowManager : public QObject
{
    Q_OBJECT

public:

    /**
     * @brief self
     * @return
     */
    static WindowManager* self();

    /**
      * @brief 获取窗口信息
      * @param windowId
      * @return
      */
    static WindowInfo getwindowInfo(const WindowId& windowId);

    /**
     * @brief 获取当前活动窗口
     * @return
     */
    static WindowId currentActiveWindow();

    /**
     * @brief 置顶窗口
     * @param windowId
     */
    static void keepWindowAbove(const WindowId& windowId);

    /**
     * @brief 获取窗口标题
     * @param windowId
     * @return
     */
     static QString getWindowTitle(const WindowId& windowId);

    /**
     * @brief 获取窗口图标
     * @param windowId
     * @return
     */
     static QIcon getWindowIcon(const WindowId& windowId);


     /**
      * @brief 获取窗口所在组的组名
      * @param windowId
      * @return
      */
     static QString getWindowGroup(const WindowId& windowId);


    /**
     * @brief 关闭窗口
     * @param windowId
     */
     static void closeWindow(const WindowId& windowId);

    /**
     * @brief 激活窗口
     * @param windowId
     */
     static void activateWindow(const WindowId& windowId);

    /**
     * @brief 最大化窗口
     * @param windowId
     */
     static void maximizeWindow(const WindowId& windowId);

    /**
     * @brief 最小化窗口
     * @param windowId
     */
     static void minimizeWindow(const WindowId& windowId);

     /**
      * @brief 获取窗口进程pid
      * @return
      */
     static quint32 getPid(const WindowId& windowId);

    /**
     * @brief 显示当前桌面
     */
     static void showDesktop();

    /**
     * @brief 取消显示当前桌面
     */
     static void hideDesktop();

     /**
     * @brief 获取当前桌面的名称
     * @return
     */
    static QString currentDesktop();

    /**
     * @brief 获取当前窗口列表
     * @return
     */
    static QList<WindowId> windows();

    /**
     * @brief 获取窗口类型，仅适用于X环境下，wayland下统一返回normal
     * @param windowId
     * @return
     */
    static NET::WindowType getWindowType(const WindowId& windowId);

    /**
     * @brief 设置窗口位置
     * @param window
     * @param rect
     */
    static void	setGeometry(QWindow *window,const QRect &rect);

    /**
     * @brief 设置是否跳过任务栏,since 2.0
     * @param window
     * @param skip
     */
    static void setSkipTaskBar(QWindow *window,bool skip);

    /**
     * @brief 设置是否跳过窗口选择,,since 2.0
     * @param window
     * @param skip
     */
    static  void setSkipSwitcher(QWindow *window,bool skip);

    /**
     * @brief 判断窗体是否跳过任务栏,since 2.0
     * @param windowId
     * @return
     */
    static bool skipTaskBar(const WindowId& windowId);

    /**
     * @brief 判断窗体是否跳过窗口选择,since 2.0
     * @param windowId
     * @return
     */
    static bool skipSwitcher(const WindowId& windowId);

    /**
     * @brief 判断桌面是否处于显示状态,,since 2.0
     * @return
     */
    static bool isShowingDesktop();

    /**
     * @brief 设置窗口在所有桌面中显示,since 2.0
     * @param wid
     */
    static void setOnAllDesktops(const WindowId &windowId);

    /**
     * @brief 判断窗口在所有桌面中显示,since 2.0
     * @param windowId
     * @return
     */
    static bool isOnAllDesktops(const WindowId &windowId);

    /**
     * @brief 判断窗口是否在当前桌面
     * @param 窗口id
     * @return
     */
    static bool isOnCurrentDesktop(const WindowId& id);

    /**
     * @brief 判断窗口是否在指定桌面
     * @param 窗口id
     * @param 桌面id
     * @return
     */
    static bool isOnDesktop(const WindowId &id, int desktop);

Q_SIGNALS:
     /**
      * @brief 窗口添加信号
      * @param windowId
      */
     void windowAdded(const WindowId& windowId);

     /**
      * @brief 窗口删除信号
      * @param windowId
      */
     void windowRemoved(const WindowId& windowId);

     /**
      * @brief 活动窗口改变信号
      * @param wid
      */
     void activeWindowChanged(const WindowId& wid);

     /**
      * @brief 窗口改变信号
      * @param wid
      */
     void windowChanged(const WindowId& wid);

     /**
      * @brief 当前桌面改变信号
      * @param wid
      */
     void currentDesktopChanged();

     /**
      * @brief 桌面显示状态变化信号
      */
     void isShowingDesktopChanged();

private:
     WindowManager(QObject *parent = nullptr);
};
}


#endif // WINDOWMANAGER_H
